<?php
import( 'de.ceus-media.framework.krypton.core.DefinitionAction' );
import( 'de.ceus-media.framework.krypton.exception.IO' );
import( 'classes.action.panel.ProjectSelector' );
import( 'classes.logic.Run' );
import( 'classes.logic.Topic' );
import( 'classes.logic.Case' );
/**
 *	Option Actions.
 *	@package		mv2.action.management
 *	@extends		Framework_Krypton_Core_DefinitionAction
 *	@uses			Logic_Licencee
 *	@uses			Action_Panel_PlatformSelector
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@since			06.08.2007
 *	@version		0.1
 */
/**
 *	Option Actions.
 *	@package		mv2.action.management
 *	@extends		Framework_Krypton_Core_DefinitionAction
 *	@uses			Logic_Licencee
 *	@uses			Action_Panel_PlatformSelector
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@since			06.08.2007
 *	@version		0.1
 */
class Action_Management_Run extends Framework_Krypton_Core_DefinitionAction
{

/*
Uferstrasse 30
15754 Senzig

*/
	/**
	 *	Constructor.
	 *	@access		public
	 *	@return		void
	 */
	public function __construct()
	{
		parent::__construct();
		$this->loadLanguage( 'management.run', 'run' );
		$this->addAction( 'addRun' );
		$this->addAction( 'editRun' );
		$this->addAction( 'startRun' );
		$this->addAction( 'closeRun' );
		$action	= new Action_Panel_ProjectSelector();
		$action->performActions();
	}
	
	protected function startRun( $runId )
	{
		$words		= $this->words['run']['msg'];
		try
		{
			Logic_Run::startRun( $runId );
		}
		catch( Exception $e )
		{
			$this->handleException( $e, 'run', 'addRun' );
		}
	}

	protected function closeRun( $runId )
	{
		$words		= $this->words['run']['msg'];
		try
		{
			Logic_Run::closeRun( $runId );
		}
		catch( Exception $e )
		{
			$this->handleException( $e, 'run', 'addRun' );
		}
	}

	protected function addRun()
	{
		$request	= Framework_Krypton_Core_Registry::getStatic( "request" );
		$words		= $this->words['run']['msg'];

		try
		{
			$logic		= new Logic_Run();
			$request->set( 'add_run_project_id', $request->get( 'projectId' ) );
			if( $logic->addRun( $request->getAll(), 'add_run_' ) )
				$this->messenger->noteSuccess( $words['success_run_added'] );
			else
				$this->messenger->noteError( $words['error_run_not_added'] );
		}
		catch( Exception $e )
		{
			$this->handleException( $e, 'run', 'addRun' );
		}
	}
	
	protected function editRun()
	{
		$request	= Framework_Krypton_Core_Registry::getStatic( "request" );
		$words		= $this->words['run']['msg'];

		$runId		= $request->get( 'runId' );
		if( $runId )
		{
			try
			{
				$logic	= new Logic_Run();
				if( $logic->editRun( $runId, $request->getAll(), 'edit_run_' ) )
					$this->messenger->noteSuccess( $words['success_run_edited'] );
				else
					$this->messenger->noteError( $words['error_run_not_edited'] );
				$request->remove( 'runId' );
			}
			catch( Exception $e )
			{
				$this->handleException( $e, 'run', 'editRun' );
			}
		}
		
	}
}
?>